
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/22/2012 15:42:15
-- Generated from EDMX file: C:\Users\Krzysiek\Documents\ProjectEnginer\SVN\Project\Server\Server\Server\ServerDataBase.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DistributedComputingPramaryBase];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_StatusProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectSet] DROP CONSTRAINT [FK_StatusProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectCompiuting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompiutingSet] DROP CONSTRAINT [FK_ProjectCompiuting];
GO
IF OBJECT_ID(N'[dbo].[FK_CompiutingUnitsCompiuting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompiutingSet] DROP CONSTRAINT [FK_CompiutingUnitsCompiuting];
GO
IF OBJECT_ID(N'[dbo].[FK_CompiutingStatusCompiuting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompiutingSet] DROP CONSTRAINT [FK_CompiutingStatusCompiuting];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientLogCompiutingUnits]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClientLogSet] DROP CONSTRAINT [FK_ClientLogCompiutingUnits];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientLogCompiuting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClientLogSet] DROP CONSTRAINT [FK_ClientLogCompiuting];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[CompiutingUnitsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompiutingUnitsSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectStatusSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectStatusSet];
GO
IF OBJECT_ID(N'[dbo].[CompiutingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompiutingSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSet];
GO
IF OBJECT_ID(N'[dbo].[CompiutingStatusSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompiutingStatusSet];
GO
IF OBJECT_ID(N'[dbo].[ClientLogSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientLogSet];
GO
IF OBJECT_ID(N'[dbo].[ServerLogSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServerLogSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'CompiutingUnitsSet'
CREATE TABLE [dbo].[CompiutingUnitsSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Guid] uniqueidentifier  NOT NULL,
    [JoinDate] datetime  NOT NULL,
    [LastActivityDate] datetime  NOT NULL,
    [Processor_Name] nvarchar(max)  NOT NULL,
    [Processor_LogicalProcess] smallint  NOT NULL,
    [LastIP] nvarchar(15)  NOT NULL
);
GO

-- Creating table 'ProjectStatusSet'
CREATE TABLE [dbo].[ProjectStatusSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'CompiutingSet'
CREATE TABLE [dbo].[CompiutingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NULL,
    [Project_Id] int  NOT NULL,
    [CompiutingUnits_Id] int  NOT NULL,
    [CompiutingStatus_Id] smallint  NOT NULL
);
GO

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(255)  NOT NULL,
    [AddDate] datetime  NOT NULL,
    [MaxDaysOfCompiuting] int  NULL,
    [EndDate] datetime  NULL,
    [Priorytet] tinyint  NOT NULL,
    [Status_Id] int  NOT NULL
);
GO

-- Creating table 'CompiutingStatusSet'
CREATE TABLE [dbo].[CompiutingStatusSet] (
    [Id] smallint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ClientLogSet'
CREATE TABLE [dbo].[ClientLogSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Message] nvarchar(1024)  NOT NULL,
    [Date] datetime  NOT NULL,
    [CompiutingUnitsId] int  NOT NULL,
    [CompiutingId] int  NULL,
    [IsError] bit  NOT NULL
);
GO

-- Creating table 'ServerLogSet'
CREATE TABLE [dbo].[ServerLogSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Message] nvarchar(max)  NOT NULL,
    [IsError] bit  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'CompiutingUnitsSet'
ALTER TABLE [dbo].[CompiutingUnitsSet]
ADD CONSTRAINT [PK_CompiutingUnitsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectStatusSet'
ALTER TABLE [dbo].[ProjectStatusSet]
ADD CONSTRAINT [PK_ProjectStatusSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CompiutingSet'
ALTER TABLE [dbo].[CompiutingSet]
ADD CONSTRAINT [PK_CompiutingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CompiutingStatusSet'
ALTER TABLE [dbo].[CompiutingStatusSet]
ADD CONSTRAINT [PK_CompiutingStatusSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ClientLogSet'
ALTER TABLE [dbo].[ClientLogSet]
ADD CONSTRAINT [PK_ClientLogSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ServerLogSet'
ALTER TABLE [dbo].[ServerLogSet]
ADD CONSTRAINT [PK_ServerLogSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Status_Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [FK_StatusProject]
    FOREIGN KEY ([Status_Id])
    REFERENCES [dbo].[ProjectStatusSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StatusProject'
CREATE INDEX [IX_FK_StatusProject]
ON [dbo].[ProjectSet]
    ([Status_Id]);
GO

-- Creating foreign key on [Project_Id] in table 'CompiutingSet'
ALTER TABLE [dbo].[CompiutingSet]
ADD CONSTRAINT [FK_ProjectCompiuting]
    FOREIGN KEY ([Project_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectCompiuting'
CREATE INDEX [IX_FK_ProjectCompiuting]
ON [dbo].[CompiutingSet]
    ([Project_Id]);
GO

-- Creating foreign key on [CompiutingUnits_Id] in table 'CompiutingSet'
ALTER TABLE [dbo].[CompiutingSet]
ADD CONSTRAINT [FK_CompiutingUnitsCompiuting]
    FOREIGN KEY ([CompiutingUnits_Id])
    REFERENCES [dbo].[CompiutingUnitsSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CompiutingUnitsCompiuting'
CREATE INDEX [IX_FK_CompiutingUnitsCompiuting]
ON [dbo].[CompiutingSet]
    ([CompiutingUnits_Id]);
GO

-- Creating foreign key on [CompiutingStatus_Id] in table 'CompiutingSet'
ALTER TABLE [dbo].[CompiutingSet]
ADD CONSTRAINT [FK_CompiutingStatusCompiuting]
    FOREIGN KEY ([CompiutingStatus_Id])
    REFERENCES [dbo].[CompiutingStatusSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CompiutingStatusCompiuting'
CREATE INDEX [IX_FK_CompiutingStatusCompiuting]
ON [dbo].[CompiutingSet]
    ([CompiutingStatus_Id]);
GO

-- Creating foreign key on [CompiutingUnitsId] in table 'ClientLogSet'
ALTER TABLE [dbo].[ClientLogSet]
ADD CONSTRAINT [FK_ClientLogCompiutingUnits]
    FOREIGN KEY ([CompiutingUnitsId])
    REFERENCES [dbo].[CompiutingUnitsSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientLogCompiutingUnits'
CREATE INDEX [IX_FK_ClientLogCompiutingUnits]
ON [dbo].[ClientLogSet]
    ([CompiutingUnitsId]);
GO

-- Creating foreign key on [CompiutingId] in table 'ClientLogSet'
ALTER TABLE [dbo].[ClientLogSet]
ADD CONSTRAINT [FK_ClientLogCompiuting]
    FOREIGN KEY ([CompiutingId])
    REFERENCES [dbo].[CompiutingSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientLogCompiuting'
CREATE INDEX [IX_FK_ClientLogCompiuting]
ON [dbo].[ClientLogSet]
    ([CompiutingId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------